import { request, config } from 'utils'

const { api } = config
const { customerAddressList, customerAddressAdd, customerAddressEdit, customerAddressDel, accoutSignAddressList, accoutSignAddressAdd, accoutSignAddressEdit, accoutSignAddressDel } = api
const { entityAddressList, entityAddressAdd, entityAddressEdit, entityAddressDel } = api
const { entityDirectorAddressList, entityDirectorAddressAdd, entityDirectorAddressEdit, entityDirectorAddressDel } = api
const { reportBaseAddressList, reportBaseAddressAdd, reportBaseAddressEdit, reportBaseAddressDel  } = api

function apiSelect (type) {
  let AddressApi = {}
  switch (type) {
    case 'customerAddress':
      AddressApi.listAPI = customerAddressList
      AddressApi.createAPI = customerAddressAdd
      AddressApi.updateAPI = customerAddressEdit
      AddressApi.delAPI = customerAddressDel
      break
    case 'signAddress':
      AddressApi.listAPI = accoutSignAddressList
      AddressApi.createAPI = accoutSignAddressAdd
      AddressApi.updateAPI = accoutSignAddressEdit
      AddressApi.delAPI = accoutSignAddressDel
      break
    case 'entityAddress':
      AddressApi.listAPI = entityAddressList
      AddressApi.createAPI = entityAddressAdd
      AddressApi.updateAPI = entityAddressEdit
      AddressApi.delAPI = entityAddressDel
      break
    case 'entityDirectorAddress':
      AddressApi.listAPI = entityDirectorAddressList
      AddressApi.createAPI = entityDirectorAddressAdd
      AddressApi.updateAPI = entityDirectorAddressEdit
      AddressApi.delAPI = entityDirectorAddressDel
      break
    case 'reportBaseAddress':
      AddressApi.listAPI = reportBaseAddressList
      AddressApi.createAPI = reportBaseAddressAdd
      AddressApi.updateAPI = reportBaseAddressEdit
      AddressApi.delAPI = reportBaseAddressDel
      break
    default:
  }
  return AddressApi
}
export async function list (params) {
  const { listAPI } = apiSelect(params.type)
  return request({
    url: listAPI,
    method: 'put',
    data: params,
  })
}

export async function create (params) {
  const { createAPI } = apiSelect(params.type)
  return request({
    url: createAPI,
    method: 'post',
    data: params.data,
  })
}

export async function update (params) {
  const { updateAPI } = apiSelect(params.type)
  return request({
    url: updateAPI,
    method: 'put',
    data: params.data,
  })
}
export async function remove (params) {
  const { delAPI } = apiSelect(params.type)
  return request({
    url: delAPI,
    method: 'delete',
    data: params,
  })
}

